#ifndef _TIMER_H_
#define _TIMER_H_

#include <buildspec.h>

#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/thread/mutex.hpp>

#include <time.h> 
#include <list> 

namespace GST{
namespace Utils{

	/**
	 * Class for measuring time on operations.
	 */
class GST_API_EXPORT Timer
{
private:

	Timer();
	Timer(const Timer&);

public:

	typedef boost::weak_ptr<Timer> TimerPtr;

	struct TimeMsg
	{
		double time_;
		std::string msg_;
		TimeMsg(const double & t, const std::string & s): time_(t), msg_(s) {}
	};

	//timer
	void start();
	void stop();
	void reset();
	void setSnooze(bool doSnooze);
	void append(const std::string msg);

	void WriteOutputAt(std::ostream & os) const;
	std::string GetOutput() const;

	//singleton patterns
    static boost::weak_ptr<Timer> GetInstance();
    static void Destroy();
 
	inline double getCurrentSec() { return (double)(clock() - _tstart)/CLOCKS_PER_SEC; }

private:

	//timer
	clock_t _tstart;
	std::list<TimeMsg> _timeBoard;
	bool _snooze;

	//singleton patterns
	static bool isInitialized;
   // static boost::mutex lockObject;
    static boost::shared_ptr<Timer> instance;
};

}//of namespace
}

#endif